<?php
	//define( 'LAYOUT_PATH', get_template_directory() . '/assets/css/skins/' );
	define( 'OPTIONS_PATH', get_template_directory_uri() . '/admin/ReduxCore/assets/' );

    if ( ! class_exists( 'CrossThemes_config' ) ) {

        class CrossThemes_config {

            public $args = array();
            public $sections = array();
            public $theme;
            public $ReduxFramework;

            public function __construct() {

                if ( ! class_exists( 'ReduxFramework' ) ) {
                    return;
                }

                // This is needed. Bah WordPress bugs.  ;)
                if ( true == Redux_Helpers::isTheme( __FILE__ ) ) {
                    $this->initSettings();
                } else {
					add_action('plugins_loaded', array($this, 'initSettings'), 10);
				}

            }

            public function initSettings() {

                // Just for demo purposes. Not needed per say.
                $this->theme = wp_get_theme();

                // Set the default arguments
                $this->setArguments();


                // Create the sections and fields
                $this->setSections();

                if ( ! isset( $this->args['opt_name'] ) ) { // No errors please
                    return;
                }

                $this->ReduxFramework = new ReduxFramework( $this->sections, $this->args );
            }


            /**
             * Filter hook for filtering the args. Good for child themes to override or add to the args array. Can also be used in other functions.
             * */
            function change_arguments( $args ) {
                //$args['dev_mode'] = true;

                return $args;
            }

            /**
             * Filter hook for filtering the default value of any given field. Very useful in development mode.
             * */
            function change_defaults( $defaults ) {
                $defaults['str_replace'] = 'Testing filter hook!';

                return $defaults;
            }

            

            public function setSections() {

                /**
                 * Used within different fields. Simply examples. Search for ACTUAL DECLARATION for field examples
                 * */
                // Background Patterns Reader
                $sample_patterns_path = ReduxFramework::$_dir . '../sample/patterns/';
                $sample_patterns_url  = ReduxFramework::$_url . '../sample/patterns/';
                $sample_patterns      = array();

                if ( is_dir( $sample_patterns_path ) ) :

                    if ( $sample_patterns_dir = opendir( $sample_patterns_path ) ) :
                        $sample_patterns = array();

                        while ( ( $sample_patterns_file = readdir( $sample_patterns_dir ) ) !== false ) {

                            if ( stristr( $sample_patterns_file, '.png' ) !== false || stristr( $sample_patterns_file, '.jpg' ) !== false ) {
                                $name              = explode( '.', $sample_patterns_file );
                                $name              = str_replace( '.' . end( $name ), '', $sample_patterns_file );
                                $sample_patterns[] = array(
                                    'alt' => $name,
                                    'img' => $sample_patterns_url . $sample_patterns_file
                                );
                            }
                        }
                    endif;
                endif;

                ob_start();

                $ct          = wp_get_theme();
                $this->theme = $ct;
                $item_name   = $this->theme->get( 'Name' );
                $tags        = $this->theme->Tags;
                $screenshot  = $this->theme->get_screenshot();
                $class       = $screenshot ? 'has-screenshot' : '';

                $customize_title = sprintf( __( 'Customize &#8220;%s&#8221;', 'redux-framework-demo' ), $this->theme->display( 'Name' ) );

                ?>
                <div id="current-theme" class="<?php echo esc_attr( $class ); ?>">
                    <?php if ( $screenshot ) : ?>
                        <?php if ( current_user_can( 'edit_theme_options' ) ) : ?>
                            <a href="<?php echo wp_customize_url(); ?>" class="load-customize hide-if-no-customize"
                               title="<?php echo esc_attr( $customize_title ); ?>">
                                <img src="<?php echo esc_url( $screenshot ); ?>"
                                     alt="<?php esc_attr_e( 'Current theme preview', 'redux-framework-demo' ); ?>"/>
                            </a>
                        <?php endif; ?>
                        <img class="hide-if-customize" src="<?php echo esc_url( $screenshot ); ?>"
                             alt="<?php esc_attr_e( 'Current theme preview', 'redux-framework-demo' ); ?>"/>
                    <?php endif; ?>

                    <h4><?php echo $this->theme->display( 'Name' ); ?></h4>

                    <div>
                        <ul class="theme-info">
                            <li><?php printf( __( 'By %s', 'redux-framework-demo' ), $this->theme->display( 'Author' ) ); ?></li>
                            <li><?php printf( __( 'Version %s', 'redux-framework-demo' ), $this->theme->display( 'Version' ) ); ?></li>
                            <li><?php echo '<strong>' . __( 'Tags', 'redux-framework-demo' ) . ':</strong> '; ?><?php printf( $this->theme->display( 'Tags' ) ); ?></li>
                        </ul>
                        <p class="theme-description"><?php echo $this->theme->display( 'Description' ); ?></p>
                        <?php
                            if ( $this->theme->parent() ) {
                                printf( ' <p class="howto">' . __( 'This <a href="%1$s">child theme</a> requires its parent theme, %2$s.', 'redux-framework-demo' ) . '</p>', __( 'http://codex.wordpress.org/Child_Themes', 'redux-framework-demo' ), $this->theme->parent()->display( 'Name' ) );
                            }
                        ?>

                    </div>
                </div>

                <?php
                $item_info = ob_get_contents();

                ob_end_clean();

                // ACTUAL DECLARATION OF SECTIONS
                $this->sections[] = array(
                    'title'  => __( 'General Settings', 'crosstheme' ),
                    'icon'   => 'el el-dashboard',
                    // 'submenu' => false, // Setting submenu to false on a given section will hide it from the WordPress sidebar menu!
                    'fields' => array(

                        array(
						'id'=>'crt_logo_upload',
						'type' => 'media', 
						'url'=> true,
						'title' => __('Logo', 'crosstheme'),
						'compiler' => 'true',
						'subtitle' => __('Upload your Logo. If left blank theme will use site name.', 'crosstheme'),
						),
                        
						array(
						'id'=>'footer_copyright',
						'type' => 'textarea',
						'title' => __('Footer Copyright Text', 'crosstheme'), 
						'subtitle' => __('Write your own copyright text here. You can use the following shortcodes in your footer text: [copyright] [site-name] [the-year]', 'virtue'),
						'default' => '[copyright] [the-year] [site-name] [theme-credit]',
						),
                    ),
                );
				
				// Layout Tab
				$this->sections[] = array(
					'icon'   => 'el el-cogs',
                    'title'  => __( 'Layout', 'crosstheme' ),
					'fields' => array(
						//Site Layout
						array(
                            'id'       => 'opt-layout',
                            'type'     => 'image_select',
                            'compiler' => true,
                            'title'    => __( 'Site Layout', 'crosstheme' ),
                            'subtitle' => __( 'Select Boxed or Wide Site Layout Style', 'crosstheme' ),
                            'options' => array(
								'wide' => array('alt' => 'Wide Layout', 'img' => OPTIONS_PATH.'img/1c.png'),
								'boxed' => array('alt' => 'Boxed Layout', 'img' => OPTIONS_PATH.'img/3cm.png'),
							),
							'default' => 'wide',
                        ),
						
						// Header Layout
						array(
                            'id'       => 'header-layout',
                            'type'     => 'image_select',
                            'compiler' => true,
                            'title'    => __( 'Header Layout', 'crosstheme' ),
                            'subtitle' => __( 'Select Boxed or Wide Header Layout Style.', 'crosstheme' ),
                            'options' => array(
								'wide' => array('alt' => 'Wide Layout', 'img' => OPTIONS_PATH.'img/1c.png'),
								'boxed' => array('alt' => 'Boxed Layout', 'img' => OPTIONS_PATH.'img/3cm.png'),
							),
							'default' => 'wide',
                        ),
						
						// Main Content Layout
						array(
                            'id'       => 'mcontent-layout',
                            'type'     => 'image_select',
                            'compiler' => true,
                            'title'    => __( 'Main Content Layout', 'crosstheme' ),
                            'subtitle' => __( 'Select Boxed or Wide Main Content Layout Style.', 'crosstheme' ),
                            'options' => array(
								'wide' => array('alt' => 'Wide Layout', 'img' => OPTIONS_PATH.'img/1c.png'),
								'boxed' => array('alt' => 'Boxed Layout', 'img' => OPTIONS_PATH.'img/3cm.png'),
							),
							'default' => 'wide',
                        ),
						
						// Main Content Layout
						array(
                            'id'       => 'footer-layout',
                            'type'     => 'image_select',
                            'compiler' => true,
                            'title'    => __( 'Footer Layout', 'crosstheme' ),
                            'subtitle' => __( 'Select Boxed or Wide Footer Layout Style.', 'crosstheme' ),
                            'options' => array(
								'wide' => array('alt' => 'Wide Layout', 'img' => OPTIONS_PATH.'img/1c.png'),
								'boxed' => array('alt' => 'Boxed Layout', 'img' => OPTIONS_PATH.'img/3cm.png'),
							),
							'default' => 'wide',
                        ),
					)
				);
				
            }

            /**
             * All the possible arguments for Redux.
             * For full documentation on arguments, please refer to: https://github.com/ReduxFramework/ReduxFramework/wiki/Arguments
             * */
            public function setArguments() {

                $theme = wp_get_theme(); // For use with some settings. Not necessary.

                $this->args = array(
                    'opt_name'             => 'crosstheme',
                    'display_name'         => $theme->get( 'Name' ),
                    'display_version'      => $theme->get( 'Version' ),
                    'menu_type'            => 'menu',
                    'allow_sub_menu'       => true,
                    'menu_title'           => __( 'Theme Options', 'redux-framework-demo' ),
                    'page_title'           => __( 'Theme Options', 'redux-framework-demo' ),
                    'google_api_key'       => '',
                    'google_update_weekly' => false,
                    'async_typography'     => true,
                    'admin_bar'            => true,
                    'admin_bar_icon'     => 'dashicons-portfolio',
                    'admin_bar_priority' => 50,
                    'global_variable'      => '',
                    'dev_mode'             => false,
                    'update_notice'        => true,
                    'customizer'           => true,
                    'page_priority'        => null,
                    //'page_parent'          => 'themes.php',
                    'page_permissions'     => 'manage_options',
                    'menu_icon'            => '',
                    'last_tab'             => '',
                    'page_icon'            => 'icon-themes',
                    'page_slug'            => 'crosstheme',
					'page_type'			   => 'submenu',
                    'save_defaults'        => true,
                    'default_show'         => false,
                    'default_mark'         => '',
                    'show_import_export'   => true,
                    'transient_time'       => 60 * MINUTE_IN_SECONDS,
                    'output'               => true,
                    'output_tag'           => true,
                    'database'             => '',
                    'system_info'          => false,
                    // More

                    // HINTS
                    'hints'                => array(
                        'icon'          => 'el el-question-sign',
                        'icon_position' => 'right',
                        'icon_color'    => 'lightgray',
                        'icon_size'     => 'normal',
                        'tip_style'     => array(
                            'color'   => 'light',
                            'shadow'  => true,
                            'rounded' => false,
                            'style'   => '',
                        ),
                        'tip_position'  => array(
                            'my' => 'top left',
                            'at' => 'bottom right',
                        ),
                        'tip_effect'    => array(
                            'show' => array(
                                'effect'   => 'slide',
                                'duration' => '500',
                                'event'    => 'mouseover',
                            ),
                            'hide' => array(
                                'effect'   => 'slide',
                                'duration' => '500',
                                'event'    => 'click mouseleave',
                            ),
                        ),
                    )
                );

            }


        }

        global $reduxConfig;
        $reduxConfig = new CrossThemes_config();
    }